﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AsmModel;

public partial class Member : System.Web.UI.MasterPage
{
    AsmEntities1 asm = new AsmEntities1();
    Cart con = new Cart();
    public void laytt()
    {
        string connstr = "SELECT * FROM tblUrlHinh WHERE idH = 1 AND ViTri= 'Logo'";
        string strurl = con.Check(connstr, 1, 0);
        imgbtnLogo.ImageUrl = "~/ImageNen/" + strurl + "";
        string strurl1 = con.LayUrlHinh(con.getIDMax("tblSanpham", 0, 0),8);
        string strurl2 = con.LayUrlHinh(con.getIDMax("tblSanpham", con.getIDMax("tblSanpham", 0, 0), 0),8);
        string strurl3 = con.LayUrlHinh(con.getIDMax("tblSanpham", con.getIDMax("tblSanpham", 0, 0), con.getIDMax("tblSanpham", con.getIDMax("tblSanpham", 0, 0), 0)),8);

        imgbtnAnh1.ImageUrl = "~/ImageNen/" + strurl1 + "";
        imgbtnAnh2.ImageUrl = "~/ImageNen/" + strurl2 + "";
        imgbtnAnh3.ImageUrl = "~/ImageNen/" + strurl3 + "";

        lblTen.Text = con.Check("SELECT * FROM tblSanpham WHERE idSP = " + con.getIDMax("tblSanpham", 0, 0) + "", 3, 0);
        lblGia.Text = con.Check("SELECT * FROM tblSanpham WHERE idSP = " + con.getIDMax("tblSanpham", 0, 0) + "", 6, 0);
        lblTen0.Text = con.Check("SELECT * FROM tblSanpham WHERE idSP = " + con.getIDMax("tblSanpham", con.getIDMax("tblSanpham", 0, 0), 0) + "", 3, 0);
        lblGia0.Text = con.Check("SELECT * FROM tblSanpham WHERE idSP = " + con.getIDMax("tblSanpham", con.getIDMax("tblSanpham", 0, 0), 0) + "", 6, 0);
        lblTen1.Text = con.Check("SELECT * FROM tblSanpham WHERE idSP = " + con.getIDMax("tblSanpham", con.getIDMax("tblSanpham", 0, 0), con.getIDMax("tblSanpham", con.getIDMax("tblSanpham", 0, 0), 0)) + "", 3, 0);
        lblGia1.Text = con.Check("SELECT * FROM tblSanpham WHERE idSP = " + con.getIDMax("tblSanpham", con.getIDMax("tblSanpham", 0, 0), con.getIDMax("tblSanpham", con.getIDMax("tblSanpham", 0, 0), 0)) + "", 6, 0);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["LoginName"] != null)
        {
            Button1.Visible = true;
            Button1.Text = "LogOut";
            lblUser.Visible = true;
            lblHello.Visible = true;
            lblUser.Text = Session["LoginName"].ToString();
            login1.Visible = false;
            Panel1.Visible = false;
        }
        if ("Admin" == Session["ChucVu"])
        {
            Response.Redirect("~/AdminHome.aspx");
        }
        laytt();        
    }
    protected void btnLogI_Click(object sender, EventArgs e)
    {   
        string connstr = "SELECT * FROM tblUsers WHERE Username = '" + txtUserName.Text.Trim() + "' AND Password= '" + txtPassWord.Text.Trim() + "'";
        if (con.Check(connstr, 0, 1) != null)
        {
            
            Session["LoginName"] = con.Check(connstr, 0, 1);
            Session["idUse"] = con.Check(connstr,0,0);
            Session["ChucVu"] = con.Check(connstr, 10, 0);
            Response.Redirect("Home.aspx");
        }
        else
        {
            lblErro.Text = "Tai khoan ,hoac mat khau khong dung.";
        }
    }
    protected void btnSerach_Click1(object sender, EventArgs e)
    {
        Session["tkTenSP"] = txtTKTenSP.Text.Trim();
        Session["tkCLSP"] = txtTKC.Text.Trim();
        Session["tkLoaiSP"] = txtTkLoaiSP.Text.Trim();
        Response.Redirect("Home.aspx");
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        if ("LogIn" == Button1.Text)
        {
            login1.Visible = true;
            Panel1.Visible = true;
            Button1.Visible = false;
        }
        else
        {
            Session["LoginName"] = null;
            Response.Redirect("Home.aspx");
        }
    }
    protected void lbtnShop_Click(object sender, EventArgs e)
    {
        Response.Redirect("Home.aspx");
    }
    protected void lbtnRegister_Click(object sender, EventArgs e)
    {
        Response.Redirect("CreateAccount.aspx");
    }
    protected void LinkButton2_Click(object sender, EventArgs e)
    {
        login1.Visible = false;
        Panel1.Visible = false;
        Button1.Visible = true;
    }
}
